from mycelery.main import app
from luffyapi.settings import constants
from .yuntongxun.sms import CCP
import logging
log = logging.getLogger("django")


@app.task(name="send_sms")
def send_sms(mobile, sms_code, sms_time):
    import time
    time.sleep(10)
    ccp = CCP()
    ret = ccp.send_template_sms(mobile, [sms_code, sms_time // 60], constants.SMS_TEMPLATE_ID)
    if ret == -1:
        log.error("发送短信失败，接收短信用户：%s" % mobile)
        return {"message": "用户注册短信发送失败！手机号：%s" % mobile}